package com.mxpio.erp.plm.service.impl;

import com.mxpio.erp.common.plm.entity.ProjectTask;
import com.mxpio.erp.common.plm.entity.ProjectTaskStatusHistory;
import com.mxpio.erp.common.plm.service.ProjectTaskStatusHistoryService;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.security.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 任务状态历史服务实现类
 */
@Service
public class ProjectTaskStatusHistoryServiceImpl extends BaseServiceImpl<ProjectTaskStatusHistory> implements ProjectTaskStatusHistoryService {

    @Override
    @Transactional
    public void record(ProjectTask projectTask, String beforeTaskStatus) {
        if(beforeTaskStatus.equals(projectTask.getExecutionStatus())){
            return;
        }
        ProjectTaskStatusHistory statusHistory = new ProjectTaskStatusHistory();
        statusHistory.setTaskCode(projectTask.getTaskCode());
        statusHistory.setTaskStatusBefore(beforeTaskStatus);
        statusHistory.setTaskStatusAfter(projectTask.getExecutionStatus());
        statusHistory.setChangeTime(projectTask.getUpdateTime());
        statusHistory.setChangeUser(projectTask.getUpdateBy());
        this.save(statusHistory);
    }
}
